/*
JavaScript code for inserting Reports widget into report thread.
*/

Widget.ready(function() {
	Widget.matchReport(function() {
		
		function postVote(vote) {
			var message = 'Voting: ' + vote.action + ' + ' + vote.violation;
			if (vote.violation == 'No Violation') {
				message = 'Voting: No Violation';
			}
			
			if (vote.comments) {
				message += '\n\n';
				message += vote.comments;
			}
			
			Thread.quickReply(message);	
		}
		
		
		Widget.bindMessageHandler('voteUpdate', function(vote) {
			postVote(vote);
		});
				
		Thread.getID(function(threadID) {
			Page.addCssFile(Environment.STYLES_URL + 'iframes.css');
			Cloud.hostedFrame({
				id: 'reportFrame',
				url: Environment.APP_URL + 'report/' + threadID,
				selector: 'div[id^="post"]',
				filter: 'first', 
				placement: 'prepend'
			});
			
			Widget.loadTrustedModule({
				script: Environment.APP_URL + 'widgets/reports/prefixChangerModule',
				name: 'prefixChangerModule'
			});
		});
	});
});
/*
	
	Widgets.match(Pattern.REPORT, function() {
		//Extract thread ID from url
		var threadID = Thread.getID();
		
		//Make the cloud frame and load CSS for it
		var frame = Cloud.frame({ url : tfx.APP_URL + 'report/' + threadID,	id : 'reportFrame' });
		
		//Set up the form submission for prefix menu retrieval.
		var form = $('#threadtools_menu form[name="threadadminform"]');
		var url = form.attr('action');
		var formData = form.serialize() + '&do=editthread';
		
		//Load the prefix menu and cloud frame
		$.post(url, formData , function(dom) {
			var menu = $('select[name="prefixid"]', dom);
			menu.attr('id', 'prefixMenu');
			menu.change(function() {
				var prefix = $(this).val();
				Thread.setPrefix(prefix, function() {
					$('#statusUpdate').show().fadeOut(3000);
				});
			});
			
			$('div[id^="post"]').first().prepend(frame).prepend('<div id="reportBar">Report Status: </div>');
			$('#reportBar').append(menu);
			$('#reportBar').append('<span id="statusUpdate">&nbsp;&nbsp;Status Updated!</span>');
			$('#statusUpdate').hide();
			$('#statusUpdate').css('color', 'green');
		});

		
	});
});
*/